Skip to content

Improve API reliability #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 150 commits into
base: main
Choose a base branch
from
Open

Improve API reliability #95

wants to merge 150 commits into from

Conversation

onmax
Copy link
Member

@onmax onmax commented Apr 3, 2025

This PR introduces changes that improve reliability, simplify code, and keep it minimal.

Warning

Actions with schedule only run on main. Therefore I have created #101 to merge just the action.

Background

When we started to create the Validators API, we had to assume different scenarios and a lot of edge cases. We also lack of different external libraries (like @nimiq/utils/albatross-policy) which made the code complex and hard to maintain.

With the present PR we aim to remove the unused code, simplify code, and add more tools/UI elements to debug easier.

Breaking changes

Please, refer to the changelog.md to see list of breaking changes.

How the API works

The API itself still works the same, we have:

  1. Fetcher: Retrieves information about ended epochs
    The code has been untouched, as this worked perfectly.
  2. Fetcher current epoch: Retrieves information about current epoch
    This step before was unclear. Now, we have a proper system to retrieve data about the current epoch. We retrieve data for any kind of validator. Please read below "kind of validators"
  3. Score computation
  4. API endpoint to retrieve endpoints. The /api/v1/validators has minimal changes, where the rest of endpoints have been heavily modified. We have never documented them so I would say it ok, however I would like to ask the community for feedback.

Note

More information about how the project works internally in the README.md of this PR!

Kind of validators

Kind Elected Tracked
ElectedTrackedValidator
ElectedUntrackedValidator
UnelectedTrackedValidator
UnelectedUntrackedValidator

tracked: Weather the validator has submitted information in GitHub.

Note

Having a UnelectedUntrackedValidator should only be when the validator has been selected for the first time in history.

The big change is how we store the information in the DB.

Before we only stored activity for elected validators. This was prune to errors since it made the code quite complex because we needed to fill in the missing data from the database at runtime.

Now, we have shifted and we store one activity per epoch per validator. The unelected validators will have missed: -1, rewarded: -1, dominanceViaSlots: -1 and likelihood: -1. The rest of fields will be filled: balance, dominanceViaBalance, stakers (new field).

Warning

We should create a system for deleted validators and stop tracking those. This is part of future work.

Range

The range is composed by the following fields:

  • fromXXX: The information for the first block/epoch we consider (~9 months). We have: fromEpoch, fromBlockNumber, fromTimestamp
  • toXXX: The information for the last block/epoch we consider. We have: toEpoch, toBlockNumber, toTimestamp
  • snapshotXXX: The information for current epoch. (It is not called currentEpoch as this could be missleading when talking about a range that is in the past). We have: snapshotEpoch, snapshotBlockNumber, snapshotTimestamp. If you have a better name, please suggest it.

Import JSON validators information

Cloudflare cannot access to the filesystem. Therefore, this PR also introduces a new mechanism to fetch the validators using ungh api.

Monorepo

This PR also simplifies monorepo configuration, having a catalog of dependencies, dev-related dependencies only in the top level (eslint, vitest, scripts), among other changes...

Out of scope

Please check out the issues tab to see which new issues will NOT be addressed in this PR

This PR closes the following issues

onmax and others added 30 commits December 23, 2024 20:40
…f their status in the network

- We know categorize validators as active or inactive
now everything is run in the root to avoid duplicating configs
@onmax
Copy link
Member Author

onmax commented May 2, 2025

Conflicts resolved, and action successfully running.

Ready for merging

@onmax onmax requested review from Albermonte and Copilot May 2, 2025 08:52
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves API reliability by simplifying components, updating sync and status logic in the main application file, and enhancing documentation and CI/CD workflows.

  • Updated Identicon component to use an identicon library and simplified its props.
  • Removed the unused Donut component.
  • Introduced improved status, sync, and environment display logic in app/app.vue.
  • Updated README, CHANGELOG, and GitHub workflows for consistency and clarity.

Reviewed Changes

Copilot reviewed 142 out of 155 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
app/components/Identicon.vue Switched to using createIdenticon and updated prop definitions.
app/components/Donut.client.vue Removed unused component logic.
app/app.vue Added status fetch, SSE sync logic, and environment UI enhancements.
README.md Updated documentation with improved visuals and corrected typos.
CHANGELOG.md Documented breaking changes and new features.
.github/workflows/nuxt-hub.yml Added deployment workflow for NuxtHub environments.
.github/workflows/ci.yml Updated CI workflow with recent Node and dependency settings.
Files not reviewed (13)
  • .env.example: Language not supported
  • .github/workflows/import-validators-mainnet.yml: Language not supported
  • .github/workflows/import-validators-testnet.yml: Language not supported
  • .github/workflows/import-validators.yml: Language not supported
  • .github/workflows/nuxthub-validators-api-mainnet.yml: Language not supported
  • .github/workflows/nuxthub-validators-api-testnet.yml: Language not supported
  • .github/workflows/pkg.new.yml: Language not supported
  • .github/workflows/release.yml: Language not supported
  • .github/workflows/sync-mainnet.yml: Language not supported
  • .github/workflows/sync-testnet.yml: Language not supported
  • .github/workflows/sync.yml: Language not supported
  • .release-it.json: Language not supported
  • .vscode/settings.json: Language not supported

return 'data:image/svg+xml,<svg width="64" height="64" viewBox="0 -4 64 64" fill="none" xmlns="http://www.w3.org/2000/svg"><path opacity=".1" d="M62.3 25.4L49.2 2.6A5.3 5.3 0 0 0 44.6 0H18.4c-1.9 0-3.6 1-4.6 2.6L.7 25.4c-1 1.6-1 3.6 0 5.2l13.1 22.8c1 1.6 2.7 2.6 4.6 2.6h26.2c1.9 0 3.6-1 4.6-2.6l13-22.8c1-1.6 1-3.6.1-5.2z" fill="url(%23identicon_radial)"/><defs><radialGradient id="identicon_radial" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="matrix(-63.0033 0 0 -56 63 56)"><stop stop-color="%23260133"/><stop offset="1" stop-color="%231F2348"/></radialGradient></defs></svg>'
return props.validator.logo
})
const { address, logo: _logo, name } = defineProps<{ logo?: string | undefined, address: string, name: string }>()
Copy link
Preview

Copilot AI May 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider extracting the props type into a separate interface or type alias to enhance readability and ease future maintenance.

Suggested change
const { address, logo: _logo, name } = defineProps<{ logo?: string | undefined, address: string, name: string }>()
type IdenticonProps = { logo?: string | undefined, address: string, name: string }
const { address, logo: _logo, name } = defineProps<IdenticonProps>()

Copilot uses AI. Check for mistakes.

}, { immediate: true })

// Also maintain the original watch for general updates
watch(() => [dataSync, syncError], debouncedRefresh)
Copy link
Preview

Copilot AI May 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider listing the reactive dependencies individually instead of wrapping them in an array to ensure clear reactivity tracking.

Suggested change
watch(() => [dataSync, syncError], debouncedRefresh)
watch([dataSync, syncError], debouncedRefresh)

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants